class Solution {
public:
    int maxProfit(vector<int>& prices) {
        int Min=INT_MAX,sum=0;
        for(auto& e:prices){
            Min=min(Min,e);
            sum=max(sum,e-Min);
        }
        return sum;
    }
};